package com.aidex.web.controller.biz;

import com.aidex.biz.domain.UserSongsTicket;
import com.aidex.biz.service.UserSongsTicketService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户获取票信息Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-07-07
 */
@RestController
@RequestMapping("/biz/bizUserSongsTicket")
public class UserSongsTicketController extends BaseController
{
    @Autowired
    private UserSongsTicketService userSongsTicketService;

    /**
     * 查询用户获取票信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:list')")
    @GetMapping("/list")
    public R<PageInfo> list(UserSongsTicket userSongsTicket, HttpServletRequest request, HttpServletResponse response)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            userSongsTicket.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
         }
        userSongsTicket.setPage(new PageDomain(request, response));
        return R.data(userSongsTicketService.findPage(userSongsTicket));
    }

    /**
     * 获取用户获取票信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:query')")
    @GetMapping(value = "/{id}")
    public R<UserSongsTicket> detail(@PathVariable("id") String id)
    {
        return R.data(userSongsTicketService.get(id));
    }

    /**
     * 新增用户获取票信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:add')")
    @Log(title = "用户获取票信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  UserSongsTicket userSongsTicket)
    {
        return R.status(userSongsTicketService.save(userSongsTicket));
    }

    /**
     * 修改用户获取票信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:edit')")
    @Log(title = "用户获取票信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated UserSongsTicket userSongsTicket)
    {
       // userSongsTicket.setUpdateTime(new Date());
        return R.status(userSongsTicketService.save(userSongsTicket));
    }


    /**
     * 删除用户获取票信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:remove')")
    @Log(title = "用户获取票信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(userSongsTicketService.deleteUserSongsTicketByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(userSongsTicketService.findMaxSort(new UserSongsTicket()));
    }

    /**
     * 导出用户获取票信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizUserSongsTicket:export')")
    @Log(title = "用户获取票信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(UserSongsTicket userSongsTicket)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    userSongsTicket.setCompanyId(null);
            }else{
                         userSongsTicket.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<UserSongsTicket> list = userSongsTicketService.findList(userSongsTicket);
        ExcelUtil<UserSongsTicket> util = new ExcelUtil<UserSongsTicket>(UserSongsTicket.class);
        return util.exportExcel(list, "用户获取票信息数据");
    }

}
